#ifndef __74HC595_H
#define __74HC595_H

#include <stdint.h>
#include "bflb_gpio.h"

#define DP_MASK (0x80)
#define DP_WRAP(num) (num | DP_MASK)
#define MINUS   0x40

extern unsigned char digit_tab[];

extern unsigned char digit_choose_bit[];

typedef struct {
    //串口数据
    uint8_t pin_ser;
    //移位寄存器时序
    uint8_t pin_clk;
    //锁存器时序
    uint8_t pin_st;
    //设置pin状态
    int (*set_dev_data)(uint8_t pin, uint8_t data);
    //延时函数
    void (*delay_fun)(uint32_t us);
    //初始化gpio
    void (*gpio_init)(uint8_t pin, uint32_t cfgset);
}digit_dev_t;

#ifdef cplusplus
extern "C" {
#endif

    //初始化设备
    void hc595_init(digit_dev_t* dev);

    /**
     *
     * @brief 动态刷新显示，需要循环调用
     * @param  dev
     * @param  number
     *          整数模式：12345678
     *          小数模式：1234.5678
     *          负数模式：-1234567
     *                  ：-1234.567
     */
    void hc595_desplay(digit_dev_t* dev, double number);

    //发送高八位，第八位数据
    void hc595_send_byte2(digit_dev_t* dev, unsigned char dataH, unsigned char dataL);

#ifdef cplusplus
}
#endif

#endif